package imvu.rbox.struct
{
	import anshe.struct.game.GUserInfo;

	public class CGamePlayerInfo extends GUserInfo
	{
		private static const MAX_WIDTH:Number	= 10;	//	地图上限宽度
		private static const MAX_HEIGHT:Number	= 20;	//	地图上限高度

		public var roomID:Number;		//	当前玩家所在房间 ID 号
		public var seatID:Number;		//	当前玩家所在的坐位号
		public var isReady:Boolean;		//	玩家是否已经准备好游戏
		public var isDead:Boolean;		//	是否已经死亡
		
		public var isPower:Boolean;		//	是否能量爆气
		public var nowPower:Number;		//	当前的能量(小于 50 的数值)
		public var nowClean:Number;		//	当前清除的行数
		public var cleanLines:Number;	//	总计清除的行数（统计值）
		
		public var gameData:Array;		//	当前游戏数据,一个 20 * 10 的二维数组
		public var gameSpeed:Number;	//	游戏运行速度		
		public var clientID:Number;		//	客户端在服务器的唯一 ID
		
		public var addScore:Number;		//	添加的成绩（仅针对游戏结束时添加）
		
		public function CGamePlayerInfo()
		{
			this.roomID = 0;
			this.seatID = 0;
			this.isReady = false;
			this.isPower = false;
			this.isDead = false;
			this.nowPower = 0;
			this.nowClean = 0;
			this.cleanLines = 0;
			this.addScore = 0;
			this.gameSpeed = 0;
			this.clientID = 0;
			this.gameData = GetArray();
		}		
		
		protected override function UpdataFromObject(obj:Object):void
		{
			super.UpdataFromObject(obj);
			
			this.roomID = obj.currentGameRoomId;
			this.seatID = Number(obj.playerSeatId);
			
			this.userID = obj.playerId;
			this.userName = obj.playerName;
			this.userNick = obj.playerNick;
			this.userFace = obj.playerHeadImg;			
			this.userScore = obj.playerScore;
			this.gameData = GetArray(obj.gameDate);
			this.isGirl = Boolean(obj.isGirl);
			this.isPower = Boolean(obj.isBaoQi);
			this.nowPower = Number(obj.power);
			this.clientID = Number(obj.ClinetId);
			
			this.isReady = Boolean(obj.isReady);			
		}
		
		private function GetArray(array:Array = null):Array
		{
			var tArray:Array = new Array();
			for(var i:int = 0; i < MAX_HEIGHT; i++)
			{
				tArray[i] = new Array();
				for(var j:int = 0; j < MAX_WIDTH; j++)
				{
					if(array)
					{
						tArray[i][j] = array.shift();
					}
					else
					{
						tArray[i][j] = 0;
					}
				}
			}
			return tArray;
		}
		
		public override function toString():String
		{
			var str:String = super.toString();
			
			return str + 
					" roomID: " + this.roomID +
					" seatID: " + this.seatID +
					" isReady: " + this.isReady	+ "\n gameData: \n" + this.gameData;
		}	
	}
}